package org.bulu.project.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.bulu.project.common.result.PageResult;
import org.bulu.project.common.result.Result;
import org.bulu.project.system.model.query.LogPageQuery;
import org.bulu.project.system.model.vo.LogPageVO;
import org.bulu.project.system.model.vo.VisitStatsVO;
import org.bulu.project.system.model.vo.VisitTrendVO;
import org.bulu.project.system.service.SysLogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;


/**
 * 日志控制层
 *
 * @author Ray
 * @since 2.10.0
 */
@RestController
@RequestMapping("/api/v1/logs")
@RequiredArgsConstructor
public class SysLogController {

    private final SysLogService logService;

    @GetMapping("/page")
    public PageResult<LogPageVO> listPagedLogs(
             LogPageQuery queryParams
    ) {
        Page<LogPageVO> result = logService.listPagedLogs(queryParams);
        return PageResult.success(result);
    }

    @GetMapping("/visit-trend")
    public Result<VisitTrendVO> getVisitTrend(
            @RequestParam String startDate,
            @RequestParam String endDate
    ) {
        LocalDate start = LocalDate.parse(startDate);
        LocalDate end = LocalDate.parse(endDate);
        VisitTrendVO data = logService.getVisitTrend(start, end);
        return Result.success(data);
    }

    @GetMapping("/visit-stats")
    public Result<List<VisitStatsVO>> getVisitStats() {
        List<VisitStatsVO> list = logService.getVisitStats();
        return Result.success(list);
    }

}
